<template>
	<a-modal
		v-model:visible="visible"
		title="异常批量处理"
		:mask-closable="false"
		:width="600"
		:destroy-on-close="true"
		@ok="handleOk"
		@cancel="handleCancel"
	>
		<a-form ref="formRef" :model="formData">
			<a-form-item label="处理描述：" name="procDesc" :rules="[{ required: true, message: '请输入处理描述' }]">
				<a-textarea v-model:value="formData.procDesc" placeholder="请输入处理描述" allow-clear/>
			</a-form-item>
			<a-form-item label="关闭异常：" name="close">
				<a-switch v-model:checked="formData.close" checked-children="是" un-checked-children="否"/>
			</a-form-item>
		</a-form>
	</a-modal>
</template>
<script setup name="bizEventExcHandleBatch">
	import { cloneDeep } from "lodash-es";
	import bizEventApi from "@/api/biz/bizEventApi";
	import { message } from "ant-design-vue";

	let visible = $ref(false)
	const emit = defineEmits({ successful: null })
	const formRef = ref()
	// 表单数据
	const formData = ref({})

	const idList = ref([])

	// 打开弹框
	const onOpen = (ids) => {
		visible = true
		idList.value = ids
		formData.value = {}
		formData.value.close = false
	}

	//确定
	const handleOk = () => {
		formRef.value
			.validate()
			.then(() => {
				bizEventApi.bizGoodsEventExcHandleBatch({
					ids: idList.value,
					procDesc: formData.value.procDesc,
					close: formData.value.close
				}).then(() => {
					message.success("异常批量处理成功")
					handleClose()
					emit('successful')
				})
			})
	}

	//关闭
	const handleClose = () => {
		formRef.value.resetFields()
		formData.value = {}
		idList.value = []
		visible = false
	}

	defineExpose({
		onOpen
	})
</script>
